// pages/list1/list1.js
const app = getApp()
var landui = require("../../utils/util.js");
const innerAudioContext = wx.createInnerAudioContext();
Page({

  /**
   * 页面的初始数据
   * 接口：hot-热门 latest-最新 next-下期预告
   */

  data: {
    domain: app.globalData.domain,
    trueDomain: app.globalData.trueDomain,
    list_column: [],
    list_hot: [],
    list_latest: [],
    list_next: [],
    length_hot:'',
    length_latest:'',
    length_next:'',
    msg:'',
    cid: 2,
    arr:[],
    current_nav: 'interview',
    option: 'pause',
    status: 'play'
  },

  // 播放音频
  playInnerAudio: function (e) {

    let that = this;
    let src = e.currentTarget.dataset.src;
    let idName = e.currentTarget.dataset.id_name;
    console.log(src);
    console.log(idName);

    innerAudioContext.autoplay = true
    innerAudioContext.src = src
    innerAudioContext.obeyMuteSwitch = false
    wx.createInnerAudioContext().title = 123
    if (that.data.option == 'pause') {
      innerAudioContext.play();
      console.log('播放');
      that.setData({
        option: 'play'
      })
    } else {
      innerAudioContext.pause();
      console.log('暂停');
      that.setData({
        option: 'pause'
      })
    }

    innerAudioContext.onError((res) => {
      console.log(res.errMsg)
      console.log(res.errCode)
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    //分类 http://jk.hnla.cn/api/audioTypes
    landui.common.post({
      module: 'audioTypes',
      success: function (res) {
        console.log(res.data);
        that.setData({
          list_column: res.data
        })
      },
      fail: function () {
      }
    }),

  
    //       http://jk.hnla.cn/api/audios?type=hot&include=expert,expert.title,expert.department&classify=1&number=4
    //       hot-热门 latest-最新 next-下期预告
    //  热门
     that.postRequest('list_hot','hot',that.data.cid);

    //  最新
    that.postRequest('list_latest', 'latest', that.data.cid);

    //  下期预告
    that.postRequest('list_next', 'next', that.data.cid);
  },

  //导航切换函数
  btnSwitch:function(e){
    var that = this;
   // console.log(e);
    var cid = e.currentTarget.dataset.cid
    that.setData({
      cid:cid
    })
    that.postRequest('list_hot', 'hot', cid);
    that.postRequest('list_latest', 'latest', that.data.cid);
    that.postRequest('list_next', 'next', that.data.cid);
  },

  //请求方法
  postRequest:function(list,type,cid){
    var that = this;
    //console.log(list);
    landui.common.post({
      module: 'audios',
      param: { include: 'expert,expert.title,expert.department', type: type, number: 3, classify: cid },
      success: function (res) {
       // console.log("is-ok");
        that.setData({
          [list]:res.data
        })
      },
      fail: function () {
      }
    })
  },



  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },


  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

})